package com.xbk.seckill.common.model.dto;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.util.StringUtils;

import java.io.Serializable;
import java.util.Date;

/**
 * 秒杀活动DTO
 *
 * @author xiexu
 * @date 2025/1/11 22:48
 */
@Data
public class SeckillActivityDTO implements Serializable {

    private static final long serialVersionUID = 1507710823959609002L;

    /**
     * 活动id
     */
    private Long id;

    /**
     * 活动名称
     */
    private String activityName;

    /**
     * 活动开始时间
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
    private Date startTime;

    /**
     * 活动结束时间
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
    private Date endTime;

    /**
     * 活动状态 0：已发布； 1：上线； -1：下线
     */
    private Integer status;

    /**
     * 活动描述
     */
    private String activityDesc;

    /**
     * 数据版本
     */
    private Long version;

    public boolean isEmpty() {
        return this.id == null
                && StringUtils.isEmpty(activityName)
                && startTime == null
                && endTime == null
                && status == null;
    }

    public boolean isFallback() {
        return id == -1001L;
    }

    public SeckillActivityDTO() {
    }

    public SeckillActivityDTO(Long id, String activityName, Date startTime, Date endTime, Integer status, String activityDesc, Long version) {
        this.id = id;
        this.activityName = activityName;
        this.startTime = startTime;
        this.endTime = endTime;
        this.status = status;
        this.activityDesc = activityDesc;
        this.version = version;
    }

}
